home *** CD-ROM | disk | FTP | other *** search
- /* $Revision Header *** Header built automatically - do not edit! ***********
- *
- * (C) Copyright 1991 by Metalworx
- *
- * Name .....: diskio.c
- * Created ..: Wed 02-Oct-91 12:15
- * Revision .: 1
- *
- * Date Author Comment
- * ========= ======== ====================
- * 20-Oct-91 Mtwx Icon fⁿr .CDM-Datei
- * 02-Oct-91 Mtwx Created this file!
- *
- * $Revision Header ********************************************************/
- #define REVISION 1
-
- /***************************************************************************
- * diskio.c: Laden und Speichern eines Molekⁿl-Datenfiles *
- ***************************************************************************/
-
- /* ------------------------------- includes ----------------------------- */
-
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <exec/libraries.h>
- #include <intuition/intuition.h>
- #include <libraries/reqbase.h>
- #include <workbench/workbench.h>
- #include <clib/req_protos.h>
- #include <req.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <proto/icon.h>
- #include <proto/arp.h>
-
- #include <mtwx_defs.h>
-
- #include "chem_defs.h"
- #include "messages.h"
- #include "cdmicon.h"
-
- /* ------------------------------- external references ------------------ */
-
- extern BOOL reqlib_used;
- extern int atomanz,ref,drehx,drehy,drehz,HEIGHT;
- extern char dn[],Titel[],Dateiname[],IFFDateiname[];
- extern ATOMTYP *a[],*alt[]; /* Atome */
- extern double zf;
- extern VEKTOR l; /* Lichtquelle */
- extern struct Window *Window1;
- extern struct Screen *FirstScreen;
- extern struct ReqLib *ReqBase;
- extern struct ReqFileRequester *FileStr;
-
- /* ------------------------------- prototypes --------------------------- */
-
- extern void Werte_loeschen(void);
- extern void SimpleRequest(char *,...);
-
- /* ------------------------------- routines ----------------------------- */
-
- int dateieinlesen()
- /* versucht, die Molekuel-Datei dn einzulesen */
- {
- char dummy[20];
- int i;
- FILE *datei;
-
- strcpy(Titel,LOAD_MOL);
- if(FileRequester(FileStr))
- {
- datei = fopen(dn, "r");
- if (datei)
- {
- Waitpointer_On(Window1,DISKWAIT);
- Werte_loeschen(); /* alte Werte loeschen */
- fgets(dummy,4,datei);
- atomanz=atoi(dummy);
- if(atomanz==0)
- {
- Waitpointer_Off(Window1);
- SimpleRequest(WRONG_DATA);
- return 0;
- }
- if(atomanz>499)
- {
- Waitpointer_Off(Window1);
- SimpleRequest(TOO_MUCH_DATA);
- return 0;
- }
- for (i = 1; i <= atomanz; i++)
- {
- a[i]=ArpAlloc(sizeof(ATOMTYP));
- alt[i]=ArpAlloc(sizeof(ATOMTYP));
- if(a[i]==NULL || alt[i]==NULL)
- /* alert!! */
- return 0;
- fgets(a[i]->name, 4, datei);
- a[i]->name[strlen(a[i]->name)-1]='\0'; /* \n loeschen */
- fgets(dummy,7,datei); a[i]->x=atoi(dummy);
- fgets(dummy,7,datei); a[i]->y=atoi(dummy);
- fgets(dummy,7,datei); a[i]->z=atoi(dummy);
- fgets(dummy,7,datei); a[i]->r=atoi(dummy);
- *alt[i] = *a[i]; /* Originale f. Editieren sichern */
- }
- fgets(dummy,19,datei); zf=atof(dummy);
- fgets(dummy,19,datei); drehx=atoi(dummy);
- fgets(dummy,19,datei); drehy=atoi(dummy);
- fgets(dummy,19,datei); drehz=atoi(dummy);
- fgets(dummy,19,datei); l.x=atof(dummy);
- fgets(dummy,19,datei); l.y=atof(dummy);
- fgets(dummy,19,datei); l.z=atof(dummy);
- fgets(dummy,19,datei); ref=atoi(dummy);
- fclose(datei);
- Waitpointer_Off(Window1);
- if (zf == 0.0 || zf > 100)
- {
- SimpleRequest(WRONG_DATA);
- return 0;
- }
- else
- return 1;
- }
- else
- return 0;
- }
- else
- return 0;
- reqlib_used=TRUE; /* wirklich benutzt! */
- }
-
- void dateispeichern(BOOL CDMIcon) /* speichert die Molekuel-Datei */
- {
- int i;
- FILE *datei;
- struct Library *IconBase;
-
- strcpy(Titel,SAVE_MOL);
- if(FileRequester(FileStr))
- {
- datei = fopen(dn, "w");
- if (datei)
- {
- Waitpointer_On(Window1,DISKWAIT);
- fprintf(datei, "%d\n", atomanz);
- for (i = 1; i <= atomanz; i++)
- {
- fprintf(datei, "%s\n", alt[i]->name);
- fprintf(datei, "%d\n", alt[i]->x);
- fprintf(datei, "%d\n", alt[i]->y);
- fprintf(datei, "%d\n", alt[i]->z);
- fprintf(datei, "%d\n", alt[i]->r);
- }
- fprintf(datei, "%lf\n", zf);
- fprintf(datei, "%d\n", drehx);
- fprintf(datei, "%d\n", drehy);
- fprintf(datei, "%d\n", drehz);
- fprintf(datei, "%lf\n", l.x);
- fprintf(datei, "%lf\n", l.y);
- fprintf(datei, "%lf\n", l.z);
- fprintf(datei, "%d\n", ref);
- fclose(datei);
- Waitpointer_Off(Window1);
- if(CDMIcon==TRUE)
- {
- IconBase = OpenLibrary("icon.library", 0);
- if (IconBase != NULL)
- {
- if (!PutDiskObject(dn, &cdmiconIcon))
- {
- DisplayBeep(0L);
- SimpleRequest(ERROR_PUT_ICON);
- }
- CloseLibrary(IconBase);
- }
- else
- SimpleRequest(NO_ICON_LIB);
- }
- }
- }
- reqlib_used=TRUE; /* wirklich benutzt! */
- }
-
- void Bild_speichern()
- {
- int i;
-
- i = strpos(Dateiname, ".cdm");
- if (i > 0)
- {
- strncpy(IFFDateiname, Dateiname, i);
- IFFDateiname[i] = '\0';
- strcat(IFFDateiname, ".iff");
- }
- strcpy(Titel,SAVE_IFF);
- strcpy(Dateiname,IFFDateiname);
- if(FileRequester(FileStr))
- {
- Waitpointer_On(Window1,DISKWAIT);
- if(!(save(dn,FirstScreen,Window1->Width,HEIGHT)))
- {
- Waitpointer_Off(Window1);
- SimpleRequest("%s", IFF_ERROR);
- }
- Waitpointer_Off(Window1);
- }
- reqlib_used=TRUE;
- }
-
-